<template>
  <div class="oper">
    <div class="title-line" content-position="left">流程处理</div>
    <p-table :show-header="false" bordered :pagination="false" :columns="columns" :data-source="tableData">
      <div slot="name" slot-scope="row">{{ row.name }} </div>
      <div slot="area" slot-scope="row">
        <div class="area" v-if="row.area === 1">
            <p-radio-group v-model="radio">
              <p-radio :value="3">
                同意
              </p-radio>
              <p-radio :value="6">
                驳回
              </p-radio>
              <p-radio @click.native="toClick" :value="9">
                转办
              </p-radio>
            </p-radio-group>
          </div>
          <div style="display: flex; justify-content: space-between;" v-if="row.area === 2">
            <p-input
              v-model="comment"
              type="textarea"
              placeholder="请输入内容"
              resize="none"
              style="width: calc( 100% - 72px)"
            /><p-button @click="submit" :loading="cLoading" class="button" type="primary">提交</p-button>
          </div>
      </div>
    </p-table>
    <lookOne :modal="true" :title="'转派'" ref="lookOne"></lookOne>
  </div>
</template>

<script>
const columns = [
  {
    title: '创建时间',
    key: 'name',
    ellipsis: true,
    align: "center",
    scopedSlots: { customRender: 'name' },
  },
  {
    title: '处理时间',
    key: 'area',
    ellipsis: true,
    scopedSlots: { customRender: 'area' },
  },
];
import Bus from '@/utils/bus'
import lookOne from "./lookOne.vue";
import process from '@/api/process'
export default {
  props: {
    taskId: String,
    step: String,
  },
  components: {
    lookOne,
  },
  data() {
    return {
      columns,
      cLoading: false,
      radio: 3 ,
      comment: '',
      tableData: [
        {
          key: '1',
          name: '操作',
          area: 1,
        },
        {
          name: '处理意见',
          key: '2',
          area: 2,
        },
      ],
    } 
  },
  methods: {
    toClick(){
      this.$refs.lookOne.startVisible = true;
    },
    submitData(){
      const params = {
        // 处理意见
        comment: this.comment,
        // 当前任务ID
        taskId: this.taskId,
        assigneeId: "",
        variables: {}
      };
      if (this.radio == 3) {
        process.completeTask(params).then(res => {
          if ( res.code === 0 ) {
            this.$message.success('同意操作提交成功');
            window.opener = null;
            window.open('', '_self');
            window.location.href="about:blank";
            window.close();
          }else {
            this.$message.error(res.msg);
          }
          this.cLoading = false;
        }).catch( r =>{
          this.cLoading = false;
        });
      } else if (this.radio == 6) {
        process.rejectTask(params).then(res => {
          if ( res.code === 0 ) {
            this.$message.success('驳回操作提交成功');
            window.opener = null;
            window.open('', '_self');
            window.location.href="about:blank";
            window.close();
          }else {
            this.$message.error(res.msg);
          }
          this.cLoading = false;
        }).catch( r =>{
          this.cLoading = false;
        });
      } else if (this.radio == 9) {
        params.assigneeId = this.$refs.lookOne.assigneeId;
        process.transferTask(params).then(res => {
          if ( res.code === 0 ) {
            this.$message.success('转办操作提交成功');
            window.opener = null;
            window.open('', '_self');
            window.location.href="about:blank";
            window.close();
          }else {
            this.$message.error(res.msg);
          }
          this.cLoading = false;
        }).catch( r =>{
          this.cLoading = false;
        });
      }
    },
    submit() {
      const that = this;
      this.cLoading = true;
      // 通知表单2保存数据
      if ( this.step && (this.step === 'b' || this.step === 'd' || this.step === 'e') ){
        Bus.$emit('prevSubmit',this.radio);
      }
      if ( this.step && (this.step === 'c') ){
        this.submitData();
      }
      
    },
  },
  mounted(){
    Bus.$on('nextSubmit',() =>{
      console.log('可以真正提交了');
      this.submitData();
    });
  },
};
</script>

<style scoped lang="less">
.oper{
  overflow: hidden;
}
 .left {
    float: left;
    width: 94px;
    padding-left: 24px;
    font-size: 14px;
    border: 1px solid rgba(226, 226, 226, 1);
  }

  .right {
    width: 890px;
    display: inline-block;
    font-size: 14px;
    border: 1px solid rgba(226, 226, 226, 1);
  }

  .right .el-radio-group {
    margin-left: 10px;
  }

  .inputArea {
    float: left;
  }

  .el-textarea__inner {
    height: 64px;
  }

  .button {
    // width: 62px;
    margin-left: 4px;
    height: 54px;
    background-color: #168FFF;
    text-align: center;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    // border-radius: 2px;
  }
  .stepName {
    margin: 36px 0px 24px 0;
    font-size: 16px;
  }
  .submitBtn{
    cursor: pointer;
    color: #fff;
  }
  .title-line{
    font-size: 16px;
    margin: 30px 0 10px 0;
  }
  .area{
    height: 40px;
    display: flex;
    align-items: center;
  }
</style>
